﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPI.Entities.Base;
using PPI.Entities.Interface;
using PPI.Entities.Kml;
using System.Xml.Serialization;
using PPI.Entities.Lookup;

namespace PPI.Entities
{
    public abstract class EBasePosition : EGoogleEarth
    {
        #region Private Members
        double m_Latitude;
        double m_Longitude;
        double m_Altitude;
        Int32 m_SatelliteCount;
        DateTime m_SatelliteTime;
        bool m_SolutionAvailable;
        EHandheld m_Handheld;
        DateTime m_Date;
        string m_Address;

        private Int32 m_ServerId;

        
        #endregion

        #region Properties
        public double Latitude
        {
            get { return m_Latitude; }
            set { m_Latitude = value; }
        }
        public double Longitude
        {
            get { return m_Longitude; }
            set { m_Longitude = value; }
        }
        public double Altitude
        {
            get { return m_Altitude; }
            set { m_Altitude = value; }
        }
        public Int32 SatelliteCount
        {
            get { return m_SatelliteCount; }
            set { m_SatelliteCount = value; }
        }
        public DateTime SatelliteTime
        {
            get { return m_SatelliteTime; }
            set { m_SatelliteTime = value; }
        }
        public bool SolutionAvailable
        {
            get { return m_SolutionAvailable; }
            set { m_SolutionAvailable = value; }
        }
        public EHandheld Handheld
        {
            get { return m_Handheld; }
            set { m_Handheld = value; }
        }
        public DateTime Date
        {
            get { return m_Date; }
            set { m_Date = value; }
        }
        public string Address
        {
            set
            {
                m_Address = value;
            }
        }
        public int ServerID
        {
            get { return m_ServerId; }
            set { m_ServerId = value; }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Generate xml code to show de position
        /// </summary>
        /// <returns></returns>
     
        protected override string GetPositionKML()
        {
            StringBuilder s = new StringBuilder();
            s.AppendLine("<Point>");
            s.AppendLine("  <coordinates>" + m_Longitude.ToString().Replace(",", ".") + "," + m_Latitude.ToString().Replace(",", ".") + " ," + m_Altitude.ToString().Replace(",", ".") + "</coordinates>");
            s.AppendLine("</Point>");
            return s.ToString();
        }

        /// <summary>
        /// Get the Icon depends the color
        /// </summary>
        /// <param name="color"></param>
        /// <returns></returns>
        protected static string GetPositionIcon(string color)
        {
            if (string.IsNullOrEmpty(color))
                return "http://www.dev-poleposition.com/IconGoogleEarthClassesI.jpg";
            else
                return "http://www.dev-poleposition.com/Images/IconGoogleEarth_" + color + ".png";
        }

        public string GetAddress()
        {
            if (string.IsNullOrEmpty(m_Address))
            {
                return Latitude.ToString().Replace(",", ".") + "," + Longitude.ToString().Replace(",", ".");
            }
            else
            {
                return m_Address;
            }
        }
       
        #endregion

        public EBasePosition()
        {
            m_Latitude = Double.MinValue;
            m_Longitude = Double.MinValue;
            m_Altitude = Double.MinValue;
            m_Address = string.Empty;
            m_Handheld = new EHandheld();
            m_ServerId = Int32.MinValue;
        }

    

        
    }
}
